import Mock from 'mockjs'
import menuData from './menu.json'
import userInfo from './userInfo.json'
Mock.setup({
  timeout: '200-2000'
})

// 测试的mock
Mock.mock('http://www.test.com/test', 'get', (req) => {
  console.log('模拟测试成功')
  return {
    code: 20000,
    data: {
      msg: 'mock测试成功'
    }
  }
})

// 模拟登录的接口
Mock.mock('http://www.test.com/login', 'post', (req) => {
  const { username, password } = JSON.parse(req.body)
  console.log(username, password);
  const res = userInfo.filter((item, index) => {
    return item.username === username
  })
  console.log(res);
  if (res.length > 0) {

    if (res[0].password === password) {
      // console.log(111);
      // 说明密码正确
      return {
        "success": true,
        "code": 20000,
        "message": "成功",
        "data": {
          "token": "eyJhbGciOiJIUzUxMiIsInppcCI6IkdaSVAifQ.H4sIAAAAAAAAAKtWKi5NUrJSSkzJzcxT0lFKrShQsjI0N7AwMTAyMjOuBQAWt9RFIAAAAA.PDeu1EileP-SfaGfZDSFKxWYZtw99_1MebBrDjLsHByBGlWqCY2B9GCoUEcmsJQmJOLiM9cW9RLHfGXPlEDZqg"
        }
      }
    } else {
      // 密码错误或者用户不存在
      return {
        "success": false,
        "code": 20001,
        "message": "密码错误",
        "data": {}
      }


    }
  }
  else {
    return {
      "success": false,
      "code": 20001,
      "message": null,
      "data": {}
    }
  }


})

// 模拟获取用户信息的接口
Mock.mock('http://www.test.com/userInfo', 'get', (req) => {
  return {
    "success": true,
    "code": 20000,
    "message": "成功",
    "data": {
      "routes": menuData,
      "buttons": [
        "cuser.detail",
        "cuser.update",
        "cuser.delete",
        "btn.User.add",
        "btn.User.remove",
        "btn.User.update",
        "btn.User.assgin",
        "btn.Role.assgin",
        "btn.Role.add",
        "btn.Role.update",
        "btn.Role.remove",
        "btn.Permission.add",
        "btn.Permission.update",
        "btn.Permission.remove",
        "btn.Activity.add",
        "btn.Activity.update",
        "btn.Activity.rule",
        "btn.Coupon.add",
        "btn.Coupon.update",
        "btn.Coupon.rule",
        "btn.OrderList.detail",
        "btn.OrderList.Refund",
        "btn.UserList.lock",
        "btn.Category.add",
        "btn.Category.update",
        "btn.Category.remove",
        "btn.Trademark.add",
        "btn.Trademark.update",
        "btn.Trademark.remove",
        "btn.Attr.add",
        "btn.Attr.update",
        "btn.Attr.remove",
        "btn.Spu.add",
        "btn.Spu.addsku",
        "btn.Spu.update",
        "btn.Spu.skus",
        "btn.Spu.delete",
        "btn.Sku.updown",
        "btn.Sku.update",
        "btn.Sku.detail",
        "btn.Sku.remove",
        "试试",
        "wef",
        "钱钱钱",
        "3123",
        "qwe",
        "123",
        "btn.User.add",
        "21321",
        "b",
        "btn.User.",
        "btn.User.",
        "12",
        "adfsdgs",
        "fgdg",
        "hjhjhj",
        "dfdf",
        "sdgfdsf",
        "111",
        "tttttt",
        "11",
        "llll",
        "ihyyhu",
        "22",
        "123",
        "test2",
        "test2",
        "aaa",
        "333",
        "functionaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
        "22",
        "12",
        "999",
        "1111",
        "9999",
        "6666",
        "22222",
        "eeee",
        "ffff",
        "7800",
        "vvvv",
        "45",
        "111",
        "111",
        "1111",
        "1111",
        "2222",
        "699",
        "8888",
        "444",
        "9999",
        "999",
        "收到速度",
        "56780-",
        "sddsdsdsdsdsdsdsdsds",
        "ghjhj",
        "tyguy",
        "99999",
        "33333",
        "99999",
        " 9999",
        " 666",
        " 777777",
        " xxx",
        " 333",
        " dsafa",
        " 555",
        " 5555",
        " 55555",
        " 555",
        " 111",
        " 213123",
        " 5555",
        " 5555",
        " 222222",
        " 11111",
        " 8888",
        " 7777",
        " 1111",
        " njjjj",
        "4444 ",
        " fdghf",
        " 555",
        " 444",
        "btn.Add1",
        "btn.Add2",
        "btn.Add3",
        "btn.Add4",
        "1-2",
        "艾斯妲",
        "666666",
        "666666",
        "5555",
        "666666",
        "66666666",
        "5555",
        "55555",
        "",
        "ndsfklghks",
        "ndsfklghks",
        "666",
        "testdelete",
        "btn.User.management",
        "btn.User.managent",
        "sasasas",
        "management",
        "btn.Add3",
        "123123"
      ],
      "roles": [
        "平台管理员"
      ],
      "name": "admin",
      "avatar": "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif"
    }
  }
})
